const router = require('koa-router')()
const {
	getBlogDetail,
	editBlog
} = require('../db/function/getblogs.js')

router.prefix('/admin')


// 修改博客
router.post('/editblog', async (ctx, next) => {
	let {
		id,
		title,
		content,
		tag,
		topImg
	} = ctx.request.body
	if (id && title && content && tag && topImg) {
		let res = await editBlog(ctx.request.body)
		if(res.affectedRows==1){
			ctx.succ('修改成功')
		}else{
			ctx.fail('修改失败')
		}
	} else {
		ctx.fail('参数不全')
	}
})

// 添加博客
router.post('/creatblog',async (ctx,next) => {
	let {
		title,
		content,
		tag,
		topImg
	} = ctx.request.body
	if (title && content && tag) {
		
	}else{
		ctx.fail('参数不全')
	}
})

module.exports = router